package com.example.a22310.myapplication.ViewModel.Club;


import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.VideoComment;
import com.example.a22310.myapplication.Listener.ClubListener;
import com.example.a22310.myapplication.Model.ClubModel;
import com.example.a22310.myapplication.databinding.ActivityVideoDetailBinding;

import java.util.List;

import static com.example.a22310.myapplication.ViewModel.Club.VideoDetailViewModel.SENDSIGN;

public class VideoCommentViewModel implements ClubListener<VideoComment> {
    private ActivityVideoDetailBinding binding;
    private AppCompatActivity activity;
    private int videoid,clubid;
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable() {
        public void run() {
            this.update();
            handler.postDelayed(this, 500);// 间隔1秒
        }
        void update() {
            if (SENDSIGN == true){
                ClubModel clubModel=new ClubModel();
                clubModel.commentList(clubid,videoid,VideoCommentViewModel.this);
                SENDFLAG = false;
            }
        }
    };


    public VideoCommentViewModel(AppCompatActivity activity, ActivityVideoDetailBinding binding,int videoid,int clubid){
        this.activity = activity;
        this.binding = binding;
        this.videoid = videoid;
        this.clubid =clubid;
        binding.setComment(this);
        ClubModel clubModel=new ClubModel();
        clubModel.commentList(clubid,videoid,VideoCommentViewModel.this);
        handler.postDelayed(runnable, 500);
    }

    @Override
    public void onSuccess(VideoComment videoComment) {
        if(videoComment.getCode()!=404){
            List<VideoComment.CommentlistBean> clubcoachlistBeen =  videoComment.getCommentlist();
            binding.recyclerViewComment.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_video_comment,
                    clubcoachlistBeen, BR.videocomm);
            binding.recyclerViewComment.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
    }

}
